package com.kaichaohulian.baocms.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.kaichaohulian.baocms.R;
import com.kaichaohulian.baocms.util.Utils;


/**
 * 仿微信对话框
 * Created by ljl on 2016/12/11.
 */
public class AddPopWindow_find extends PopupWindow {
    private View conentView;
    private Context context;
    private TextView tvGirl, tvBoy, tvAll, tvGreet, tvClear, tvCancel;

    @SuppressLint("InflateParams")
    public AddPopWindow_find(final Activity context) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.pop_nearby_list, null);
        this.context = context;
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        /*// 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.WRAP_CONTENT);*/
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);

        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimationPreview);

        tvGirl = (TextView) conentView.findViewById(R.id.ll_pop_near_girl);
        tvBoy = (TextView) conentView.findViewById(R.id.ll_pop_near_boy);
        tvAll = (TextView) conentView.findViewById(R.id.ll_pop_near_all);
        tvGreet = (TextView) conentView.findViewById(R.id.ll_pop_near_greet);
        tvClear = (TextView) conentView.findViewById(R.id.ll_pop_near_clear);
        tvCancel = (TextView) conentView.findViewById(R.id.ll_pop_near_cancel);


    }

    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(parent, 0, 0);
            this.showAtLocation(parent, Gravity.BOTTOM,0,0);

//            addPopWindowFind.showAtLocation(activity_main, Gravity.BOTTOM, 0, 0);
        } else {
            this.dismiss();
        }
    }

    public void showPopupWindowright(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            int flagdata = -(Utils.px2dip(context, 200f));
            this.showAsDropDown(parent, -200, 0);
        } else {
            this.dismiss();
        }
    }
}
